package com.ruoyi.activieadmin.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.activieadmin.mapper.AaActiveMapper;
import com.ruoyi.activieadmin.service.IAaActiveService;
import com.ruoyi.activieadmin.domain.AaActive;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Value;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Map;

/**
 * @Description  
 * @Author kemonvvv
 * @Date 2023-06-07 
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class AaActiveServiceImpl implements IAaActiveService {


    @Resource
    private AaActiveMapper aaActiveMapper;
    
    

    
    
    /**
     * 全查询
     * 
     * @param pageDomain 分页信息
     * @param aaActive 要查询的实体类
     * @return 结果
     */
    @Override
    public Page<AaActive> getAaActivePage(PageDomain pageDomain, AaActive aaActive) {
        if (Objects.isNull(aaActive)) {
            return new Page<>();
        }
        try {
            LambdaQueryWrapper<AaActive> queryWrapper = new LambdaQueryWrapper<>(new AaActive());
            //if(!Objects.isNull(aaActive.getName())){
            //	queryWrapper.like(AaActive::getName,aaActive.getName());
            //}
            

            if (!Objects.isNull(aaActive.getId())) {
                queryWrapper.eq(AaActive::getId, aaActive.getId());
            }

            if (!Objects.isNull(aaActive.getTitleText())) {
                queryWrapper.like(AaActive::getTitleText, aaActive.getTitleText());
            }

            if (!Objects.isNull(aaActive.getParams().get("StartTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("StartTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("StartTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getStartTime, aaActive.getParams().get("StartTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("StartTimeEndTime"))){
                    queryWrapper.gt(AaActive::getStartTime, aaActive.getParams().get("StartTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("StartTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("StartTimeEndTime"))) {
                    queryWrapper.between(AaActive::getStartTime, aaActive.getParams().get("StartTimeBeginTime"), aaActive.getParams().get("StartTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getParams().get("OverTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("OverTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("OverTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getOverTime, aaActive.getParams().get("OverTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("OverTimeEndTime"))){
                    queryWrapper.gt(AaActive::getOverTime, aaActive.getParams().get("OverTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("OverTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("OverTimeEndTime"))) {
                    queryWrapper.between(AaActive::getOverTime, aaActive.getParams().get("OverTimeBeginTime"), aaActive.getParams().get("OverTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getTimeDetailText())) {
                queryWrapper.like(AaActive::getTimeDetailText, aaActive.getTimeDetailText());
            }

            if (!Objects.isNull(aaActive.getOnepersonFee())) {
                queryWrapper.like(AaActive::getOnepersonFee, aaActive.getOnepersonFee());
            }

            if (!Objects.isNull(aaActive.getPhotoUrl())) {
                queryWrapper.like(AaActive::getPhotoUrl, aaActive.getPhotoUrl());
            }

            if (!Objects.isNull(aaActive.getPosition())) {
                queryWrapper.like(AaActive::getPosition, aaActive.getPosition());
            }

            if (!Objects.isNull(aaActive.getLatitude())) {
                queryWrapper.like(AaActive::getLatitude, aaActive.getLatitude());
            }

            if (!Objects.isNull(aaActive.getLongitude())) {
                queryWrapper.like(AaActive::getLongitude, aaActive.getLongitude());
            }

            if (!Objects.isNull(aaActive.getPraiseNum())) {
                queryWrapper.like(AaActive::getPraiseNum, aaActive.getPraiseNum());
            }

            if (!Objects.isNull(aaActive.getStatus())) {
                queryWrapper.like(AaActive::getStatus, aaActive.getStatus());
            }

            if (!Objects.isNull(aaActive.getDelFlag())) {
                queryWrapper.like(AaActive::getDelFlag, aaActive.getDelFlag());
            }

            if (!Objects.isNull(aaActive.getCreateBy())) {
                queryWrapper.like(AaActive::getCreateBy, aaActive.getCreateBy());
            }

            if (!Objects.isNull(aaActive.getParams().get("CreateTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("CreateTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("CreateTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getCreateTime, aaActive.getParams().get("CreateTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("CreateTimeEndTime"))){
                    queryWrapper.gt(AaActive::getCreateTime, aaActive.getParams().get("CreateTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("CreateTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("CreateTimeEndTime"))) {
                    queryWrapper.between(AaActive::getCreateTime, aaActive.getParams().get("CreateTimeBeginTime"), aaActive.getParams().get("CreateTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getUpdateBy())) {
                queryWrapper.like(AaActive::getUpdateBy, aaActive.getUpdateBy());
            }

            if (!Objects.isNull(aaActive.getParams().get("UpdateTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("UpdateTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("UpdateTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getUpdateTime, aaActive.getParams().get("UpdateTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("UpdateTimeEndTime"))){
                    queryWrapper.gt(AaActive::getUpdateTime, aaActive.getParams().get("UpdateTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("UpdateTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("UpdateTimeEndTime"))) {
                    queryWrapper.between(AaActive::getUpdateTime, aaActive.getParams().get("UpdateTimeBeginTime"), aaActive.getParams().get("UpdateTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getRemark())) {
                queryWrapper.like(AaActive::getRemark, aaActive.getRemark());
            }
        Page<AaActive> aaActiveList= aaActiveMapper.selectPage(pageDomain.getPage(), queryWrapper);
        for(AaActive record:aaActiveList.getRecords()){
        }

            return aaActiveList;
        } catch (Exception e) {
            e.printStackTrace();
            return new Page<>();
        }
    }
    

    
    /**
     * 查询通过id
     * 
     * @param id 实体类的主键
     * @return 结果
     */
    @Override
    public AaActive getAaActiveById(Long id) {
        if (Objects.isNull(id)) {
            return new AaActive();
        }
        try {
            AaActive aaActive = aaActiveMapper.selectById(id);
            if (Objects.isNull(aaActive)){
                aaActive = new AaActive();
            }
            return aaActive;

        } catch (Exception e) {
            e.printStackTrace();
            return new AaActive();
        }
    }


    
    
    /**
     * 通过类查询的属性值 id列表
     * 
     * @param aaActive 要查询的实体类
     * @return 结果
     */
    @Override
    public List<Long> getIdListByAaActive(AaActive aaActive) {
        if (Objects.isNull(aaActive)) {
            return new ArrayList<>();
        }
        try {
            LambdaQueryWrapper<AaActive> queryWrapper = new LambdaQueryWrapper<>(new AaActive());
            

            if (!Objects.isNull(aaActive.getId())) {
                queryWrapper.eq(AaActive::getId, aaActive.getId());
            }

            if (!Objects.isNull(aaActive.getTitleText())) {
                queryWrapper.like(AaActive::getTitleText, aaActive.getTitleText());
            }

            if (!Objects.isNull(aaActive.getParams().get("StartTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("StartTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("StartTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getStartTime, aaActive.getParams().get("StartTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("StartTimeEndTime"))){
                    queryWrapper.gt(AaActive::getStartTime, aaActive.getParams().get("StartTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("StartTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("StartTimeEndTime"))) {
                    queryWrapper.between(AaActive::getStartTime, aaActive.getParams().get("StartTimeBeginTime"), aaActive.getParams().get("StartTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getParams().get("OverTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("OverTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("OverTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getOverTime, aaActive.getParams().get("OverTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("OverTimeEndTime"))){
                    queryWrapper.gt(AaActive::getOverTime, aaActive.getParams().get("OverTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("OverTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("OverTimeEndTime"))) {
                    queryWrapper.between(AaActive::getOverTime, aaActive.getParams().get("OverTimeBeginTime"), aaActive.getParams().get("OverTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getTimeDetailText())) {
                queryWrapper.like(AaActive::getTimeDetailText, aaActive.getTimeDetailText());
            }

            if (!Objects.isNull(aaActive.getOnepersonFee())) {
                queryWrapper.like(AaActive::getOnepersonFee, aaActive.getOnepersonFee());
            }

            if (!Objects.isNull(aaActive.getPhotoUrl())) {
                queryWrapper.like(AaActive::getPhotoUrl, aaActive.getPhotoUrl());
            }

            if (!Objects.isNull(aaActive.getPosition())) {
                queryWrapper.like(AaActive::getPosition, aaActive.getPosition());
            }

            if (!Objects.isNull(aaActive.getLatitude())) {
                queryWrapper.like(AaActive::getLatitude, aaActive.getLatitude());
            }

            if (!Objects.isNull(aaActive.getLongitude())) {
                queryWrapper.like(AaActive::getLongitude, aaActive.getLongitude());
            }

            if (!Objects.isNull(aaActive.getPraiseNum())) {
                queryWrapper.like(AaActive::getPraiseNum, aaActive.getPraiseNum());
            }

            if (!Objects.isNull(aaActive.getStatus())) {
                queryWrapper.like(AaActive::getStatus, aaActive.getStatus());
            }

            if (!Objects.isNull(aaActive.getDelFlag())) {
                queryWrapper.like(AaActive::getDelFlag, aaActive.getDelFlag());
            }

            if (!Objects.isNull(aaActive.getCreateBy())) {
                queryWrapper.like(AaActive::getCreateBy, aaActive.getCreateBy());
            }

            if (!Objects.isNull(aaActive.getParams().get("CreateTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("CreateTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("CreateTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getCreateTime, aaActive.getParams().get("CreateTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("CreateTimeEndTime"))){
                    queryWrapper.gt(AaActive::getCreateTime, aaActive.getParams().get("CreateTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("CreateTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("CreateTimeEndTime"))) {
                    queryWrapper.between(AaActive::getCreateTime, aaActive.getParams().get("CreateTimeBeginTime"), aaActive.getParams().get("CreateTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getUpdateBy())) {
                queryWrapper.like(AaActive::getUpdateBy, aaActive.getUpdateBy());
            }

            if (!Objects.isNull(aaActive.getParams().get("UpdateTimeBeginTime"))||!Objects.isNull(aaActive.getParams().get("UpdateTimeEndTime"))) {
                if (Objects.isNull(aaActive.getParams().get("UpdateTimeBeginTime"))){
                    queryWrapper.lt(AaActive::getUpdateTime, aaActive.getParams().get("UpdateTimeEndTime"));
                }
                if (Objects.isNull(aaActive.getParams().get("UpdateTimeEndTime"))){
                    queryWrapper.gt(AaActive::getUpdateTime, aaActive.getParams().get("UpdateTimeBeginTime"));
                }
                if (!Objects.isNull(aaActive.getParams().get("UpdateTimeBeginTime")) && !Objects.isNull(aaActive.getParams().get("UpdateTimeEndTime"))) {
                    queryWrapper.between(AaActive::getUpdateTime, aaActive.getParams().get("UpdateTimeBeginTime"), aaActive.getParams().get("UpdateTimeEndTime"));
                }
            }

            if (!Objects.isNull(aaActive.getRemark())) {
                queryWrapper.like(AaActive::getRemark, aaActive.getRemark());
            }

            List<AaActive> aaActives = aaActiveMapper.selectList(queryWrapper);
            List<Long> idList = new ArrayList<>();
            for (AaActive aaActiveNo:aaActives){
                idList.add(aaActiveNo.getId());
            }
            return idList;
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    }

    
    /**
     * 添加
     * 
     * @param aaActive 要添加的实体类
     * @return 结果
     */
    @Override
    public int insertAaActive(AaActive aaActive) {
        if (Objects.isNull(aaActive)) {
            return -1;
        }
        try {
        
            //aaActive.setSpell(PinYin.getPinYin(aaActive.getName()));
            return aaActiveMapper.insert(aaActive);
        } catch (Exception e) {
            return -1;
        }
    }

    /**
     * 更新通过id进行更新一条
     * 
     * @param aaActive 实体类
     * @return 结果
     */
    @Override
    public int updateAaActiveById(AaActive aaActive) {
        if (Objects.isNull(aaActive)) {
            return -1;
        }
        try {
            //aaActive.setSpell(PinYin.getPinYin(aaActive.getName()));
            return aaActiveMapper.updateById(aaActive);
        } catch (Exception e) {
            return -1;
        }
    }
    
    /**
     * 删除通过id集合
     * 
     * @param idList id集合
     * @return 结果
     */
    @Override
    public int deleteAaActiveByIdList(List idList){
        if (Objects.isNull(idList)) {
            return -1;
        }
        try {
            return aaActiveMapper.deleteBatchIds(idList);
        } catch (Exception e) {
            return -1;
        }
    }
    
    /**
     * 查询无条件全部 用于导出
     * 
     * @return 结果
     */
    @Override
    public List<AaActive> getAaActiveList() {
        try {
            LambdaQueryWrapper<AaActive> queryWrapper = new LambdaQueryWrapper<>(new AaActive());
            queryWrapper.isNotNull(AaActive::getId);
            return aaActiveMapper.selectList(queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    }

}
